package au.com.helloweb.androidgamepractice.planegame2;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class Boom {
	private Bitmap bmpBoom;//boom image
	private int boomX,boomY;//boom location
	
	//boom image include many small images, all boom images have been put one image
	//so we should get a small rectangle to display one frame of them
	private int currentFrameIndex;//current frame index
	private int totalFrames;//count of all frames
	private int frameW,frameH;//frame width and height of image
	private boolean playEnd;//play end or not
	
	public Boom(Bitmap bmpBoom,int boomX,int boomY,int totalFrames){
		this.bmpBoom = bmpBoom;
		this.boomX = boomX;
		this.boomY = boomY;
		this.totalFrames = totalFrames;
		frameW = bmpBoom.getWidth()/totalFrames;
		frameH = bmpBoom.getHeight();
	}
	
	/*
	 * boom image display by queue, then disappeared.
	 * so we save canvas's all old image status, after display boom images,
	 * then restore to return old image status
	 */
	public void draw(Canvas canvas,Paint paint){
		canvas.save();
		canvas.clipRect(boomX, boomY, boomX+frameW, boomY+frameH);
		canvas.drawBitmap(bmpBoom, boomX-currentFrameIndex*frameW, boomY, paint);
		canvas.restore();
	}
	
	public void login(){
		if(currentFrameIndex < totalFrames){
			currentFrameIndex++;
		}else{
			playEnd = true;
		}
	}
	
	public boolean getPlayEnd(){
		return playEnd;
	}
}
